package Day010_排序算法_异常.demo07_自定义异常.自定义异常练习;

/**
 * @Author：pengzhilin
 * @Date: 2020/4/27 14:54
 */
public class Student {

    private String name;

    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        if (age < 0){
            // 传入的年龄有问题,产生异常
            throw new AgeException("年龄负数,"+age);
        }else{
            this.age = age;
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age < 0){
            // 传入的年龄有问题,产生异常
            throw new AgeException("年龄负数,"+age);
        }else{
            this.age = age;
        }
    }
}
